package top.chenfu.provider;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @Author: romantic_ke@163.com
 * @Description: 消息生产者（发送者）
 * @Date: 2019/8/13 22:18
 */
@Component
public class LogProvider {

    @Autowired
    private AmqpTemplate amqpTemplate;

    /**
     * 注入交换器，通过名称注入
     */
    @Value("${mq.config.exchange}")
    private String exchange;

    /**
     * 注入路由键
     */
    @Value("${mq.config.queue.error.routing.key}")
    private String errorRoutingKey;

    @Value("${mq.config.queue.info.routing.key}")
    private String infoRoutingKey;

    public void sendAll(String msg) {
        this.amqpTemplate.convertAndSend(this.exchange, this.infoRoutingKey, msg);
        this.amqpTemplate.convertAndSend(this.exchange, this.errorRoutingKey, msg);
    }

    public void sendInfo(String msg) {
        this.amqpTemplate.convertAndSend(this.exchange, this.infoRoutingKey, msg);
    }

    public void sendError(String msg) {
        this.amqpTemplate.convertAndSend(this.exchange, this.errorRoutingKey, msg);
    }
}
